﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.equipment
{
    /// <summary>
    /// 炼化服务
    /// </summary>
    public class PolishServer : LogicServer
    {
        public PolishServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Polish; ServerReadableName = ConfigStrings.SR_Polish; }
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            frm.chk_polish_enable.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");
            int reserve_count = 5, reserve_item_count = 5, gold_merge_attrib = 10, melt_failcount = 2;
            if (conf.ContainsKey(ConfigStrings.reserve_count)) Int32.TryParse(conf[ConfigStrings.reserve_count], out reserve_count);
            if (conf.ContainsKey(ConfigStrings.reserve_item_count)) Int32.TryParse(conf[ConfigStrings.reserve_item_count], out reserve_item_count);
            if (conf.ContainsKey(ConfigStrings.melt_failcount)) Int32.TryParse(conf[ConfigStrings.melt_failcount], out melt_failcount);
            if (conf.ContainsKey(ConfigStrings.gold_merge_attrib)) Int32.TryParse(conf[ConfigStrings.gold_merge_attrib], out gold_merge_attrib);

            frm.num_polish_reserve.Value = reserve_count;
            frm.num_polish_item_reserve.Value = reserve_item_count;
            frm.num_polish_melt_failcount.Value = melt_failcount;
            frm.num_polish_goon.Value = gold_merge_attrib;
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_polish_enable.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.reserve_count, frm.num_polish_reserve.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.reserve_item_count, frm.num_polish_item_reserve.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.melt_failcount, frm.num_polish_melt_failcount.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.gold_merge_attrib, frm.num_polish_goon.Value.ToString());
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.reserve_count, "5"); // 保留次数
            conf.setConfig(ServerName, ConfigStrings.reserve_item_count, "5"); // 保留个数
            conf.setConfig(ServerName, ConfigStrings.melt_failcount, "2"); // 几次炼化不升点就融化
            conf.setConfig(ServerName, ConfigStrings.gold_merge_attrib, "10"); // 金币炼化, 如果5次属性大于这个值
            renderSettings();
        }
        
    }
}
